home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / system-tools-backends-2.0 / scripts / Users / Shells.pm < prev    next >
Encoding:
Perl POD Document  |  2009-04-09  |  3.2 KB  |  127 lines

  1. #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. #
  3. # Copyright (C) 2000-2001 Ximian, Inc.
  4. #
  5. # Authors: Hans Petter Jansson <hpj@ximian.com>,
  6. #          Arturo Espinosa <arturo@ximian.com>,
  7. #          Tambet Ingo <tambet@ximian.com>.
  8. #          Grzegorz Golawski <grzegol@pld-linux.org> (PLD Support)
  9. #          Carlos Garnacho <carlosg@gnome.org>
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU Library General Public License as published
  13. # by the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU Library General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Library General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  24.  
  25. package Users::Shells;
  26.  
  27. use Utils::Util;
  28. use Utils::Report;
  29. use Utils::File;
  30. use Utils::Replace;
  31.  
  32. # Totally generic atm
  33. $shells_file = "/etc/shells";
  34.  
  35. sub get_files
  36. {
  37.   return $shells_file;
  38. }
  39.  
  40. sub push_shell
  41. {
  42.   my ($shells, $shell) = @_;
  43.  
  44.   $$shells{$shell} = 1 if (stat ($shell));
  45. }
  46.  
  47. sub get
  48. {
  49.   my ($ifh, %shells, $shell, @arr);
  50.  
  51.   # Init shells, I think every *nix has /bin/false.
  52.   &push_shell (\%shells, "/bin/false");
  53.  
  54.   if ($Utils::Backend::tool{"system"} eq "SunOS")
  55.   {
  56.     #SunOS doesn't have anything like /etc/shells
  57.     my $possible_shells =
  58.       [ "/bin/bash", "/bin/csh", "/bin/jsh", "/bin/ksh", "/bin/pfcsh", "/bin/pfksh", "/bin/pfsh", "/bin/sh",
  59.         "/bin/tcsh", "/bin/zsh", "/sbin/jsh", "/sbin/jsh", "/sbin/pfsh", "/sbin/sh", "/usr/bin/bash",
  60.         "/usr/bin/csh", "/usr/bin/jsh", "/usr/bin/ksh", "/usr/bin/pfcsh", "/usr/bin/pfksh", "/usr/bin/pfsh",
  61.         "/usr/bin/sh", "/usr/bin/tcsh", "/usr/bin/zsh", "/usr/xpg4/bin/sh" ];
  62.  
  63.     foreach $shell (@$possible_shells)
  64.     {
  65.       &push_shell (\%shells, $shell);
  66.     }
  67.   }
  68.   else
  69.   {
  70.     $ifh = &Utils::File::open_read_from_names($shells_file);
  71.  
  72.     while (<$ifh>)
  73.     {
  74.       next if &Utils::Util::ignore_line ($_);
  75.       chomp;
  76.       &push_shell (\%shells, $_);
  77.     }
  78.  
  79.     &Utils::File::close_file ($ifh);
  80.   }
  81.  
  82.   foreach $i (keys (%shells)) {
  83.     push @arr, $i;
  84.   }
  85.  
  86.   return \@arr;
  87. }
  88.  
  89. sub set
  90. {
  91.   my ($shells) = @_;
  92.   my ($buff, $line, $nline);
  93.  
  94.   #SunOS doesn't have /etc/shells
  95.   return if ($Utils::Backend::tool{"system"} eq "SunOS");
  96.  
  97.   $buff = &Utils::File::load_buffer ($shells_file);
  98.   return unless $buff;
  99.  
  100.   &Utils::File::join_buffer_lines ($buff);
  101.   $nline = 0;
  102.  
  103.   # delete all file entries that really exist,
  104.   # this is done for not deleting entries that
  105.   # might be installed later
  106.   while ($nline <= $#$buff)
  107.   {
  108.     $line = $$buff[$nline];
  109.     chomp $line;
  110.  
  111.     if (!&Utils::Util::ignore_line ($line))
  112.     {
  113.       delete $$buff[$nline] if (stat ($line));
  114.     }
  115.  
  116.     $nline++;
  117.   }
  118.  
  119.   # Add shells list
  120.   foreach $line (@$shells)
  121.   {
  122.     push @$buff, "$line\n" if (stat ($line));
  123.   }
  124.  
  125.   &Utils::File::save_buffer ($buff, $shells_file);
  126. }
  127.